XML Web Services |
您所在的位置:网站首页 › web service namespace › XML Web Services |
XML Web Services
❮ Previous
Next ❯
Web services are web application components. Web services can be published, found, and used on the Web. This tutorial introduces WSDL, SOAP, RDF, and RSS. WSDL WSDL stands for Web Services Description Language WSDL is an XML-based language for describing Web services. WSDL is a W3C recommendation SOAP SOAP stands for Simple Object Access Protocol SOAP is an XML based protocol for accessing Web Services. SOAP is based on XML SOAP is a W3C recommendation RDF RDF stands for Resource Description Framework RDF is a framework for describing resources on the web RDF is written in XML RDF is a W3C Recommendation RSS RSS stands for Really Simple Syndication RSS allows you to syndicate your site content RSS defines an easy way to share and view headlines and content RSS files can be automatically updated RSS allows personalized views for different sites RSS is written in XML What You Should Already KnowBefore you study web services you should have a basic understanding of XML and XML Namespaces. If you want to study these subjects first, please read our XML Tutorial. Web Services Web services are application components Web services communicate using open protocols Web services are self-contained and self-describing Web services can be discovered using UDDI Web services can be used by other applications HTTP and XML is the basis for Web services Interoperability has Highest PriorityWhen all major platforms could access the Web using Web browsers, different platforms couldn't interact. For these platforms to work together, Web-applications were developed. Web-applications are simply applications that run on the web. These are built around the Web browser standards and can be used by any browser on any platform. Web Services take Web-applications to the Next LevelBy using Web services, your application can publish its function or message to the rest of the world. Web services use XML to code and to decode data, and SOAP to transport it (using open protocols). With Web services, your accounting department's Win 2k server's billing system can connect with your IT supplier's UNIX server. Web Services have Two Types of UsesReusable application-components. There are things applications need very often. So why make these over and over again? Web services can offer application-components like: currency conversion, weather reports, or even language translation as services. Connect existing software. Web services can help to solve the interoperability problem by giving different applications a way to link their data. With Web services you can exchange data between different applications and different platforms. Any application can have a Web Service component. Web Services can be created regardless of programming language. A Web Service ExampleIn the following example we will use ASP.NET to create a simple Web Service that converts the temperature from Fahrenheit to Celsius, and vice versa: Imports System Imports System.Web.Services Public Class TempConvert :Inherits WebService Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As String dim fahr fahr=trim(replace(Fahrenheit,",",".")) if fahr="" or IsNumeric(fahr)=false then return "Error" return ((((fahr) - 32) / 9) * 5) end function Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String dim cel cel=trim(replace(Celsius,",",".")) if cel="" or IsNumeric(cel)=false then return "Error" return ((((cel) * 9) / 5) + 32) end function end class This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web Services. Example ExplainedNote: To run this example, you will need a .NET server. The first line in the example states that this is a Web Service, written in VBScript, and has the class name "TempConvert": The next lines import the namespace "System.Web.Services" from the .NET framework: Imports System Imports System.Web.ServicesThe next line defines that the "TempConvert" class is a WebService class type: Public Class TempConvert :Inherits WebServiceThe next steps are basic VB programming. This application has two functions. One to convert from Fahrenheit to Celsius, and one to convert from Celsius to Fahrenheit. The only difference from a normal application is that this function is defined as a "WebMethod()". Use "WebMethod()" to convert the functions in your application into web services: Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As String dim fahr fahr=trim(replace(Fahrenheit,",",".")) if fahr="" or IsNumeric(fahr)=false then return "Error" return ((((fahr) - 32) / 9) * 5) end functionPublic Function CelsiusToFahrenheit(ByVal Celsius As String) As String dim cel cel=trim(replace(Celsius,",",".")) if cel="" or IsNumeric(cel)=false then return "Error" return ((((cel) * 9) / 5) + 32) end function Then, end the class: end classPublish the .asmx file on a server with .NET support, and you will have your first working Web Service. Put the Web Service on Your Web SiteUsing a form and the HTTP POST method, you can put the web service on your site, like this: How To Do ItHere is the code to add the Web Service to a web page: Fahrenheit to Celsius:Celsius to Fahrenheit: Substitute the "tempconvert.asmx" with the address of your web service like: http://www.example.com/xml/tempconvert.asmx ❮ Previous Next ❯ |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |